package me.yiyou.meihua.ui.page.sixlines

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import me.yiyou.meihua.R
import me.yiyou.meihua.ui.page.memory.MemoryViewModel
import java.util.regex.Pattern

// 基础变量
var liu = intArrayOf()
var wu = intArrayOf()
var si = intArrayOf()
var san = intArrayOf()
var er = intArrayOf()
var yi = intArrayOf()

var bianliu = 999
var bianwu = 999
var biansi = 999
var biansan = 999
var bianger = 999
var bianyi = 999

var shang = 999
var xia = 999

var bianshang = 999
var bianxia = 999

val memoryViewiewModel: MemoryViewModel = MemoryViewModel()

var guaGong = ""
var fiveElements by mutableStateOf("")

@Composable
fun SixLinesCreatePage(viewModel: SixLineViewModel = viewModel()) {

    sixLinesCreateContent(viewModel.lineArray.value)

    LaunchedEffect(Unit) {
        memoryViewiewModel.loadGuaData()
    }

    Column(
        modifier = Modifier
            .padding(top = 60.dp)
            .fillMaxWidth()
            .fillMaxHeight()
    ) {

        Row(
            modifier = Modifier
                .fillMaxWidth()
                .padding(horizontal = 16.dp),
            horizontalArrangement = Arrangement.SpaceBetween,
            verticalAlignment = Alignment.CenterVertically
        ) {
            Column {
                // 绘制内外卦
                drawPartGua(shang, liu, wu, si, 1)
                drawPartGua(xia, san, er, yi, 2)
            }
            // 绘制变卦
            Column {
                drawBianPartGua(bianshang, 1)
                drawBianPartGua(bianxia, 2)
            }
        }
    }
}

/**
 * 提取元素
 */
fun extractElementFromText(text: String): String? {
    val regex = Pattern.compile("\\((.*?)\\)")
    val matcher = regex.matcher(text)
    return if (matcher.find()) {
        matcher.group(1)
    } else {
        null
    }
}

/**
 * 绘制内外卦,纳甲
 * part 卦, item3, item2, item1, 具体卦爻, position 内外卦, 1外,2内
 */
@Composable
fun drawPartGua(part: Int, item3: IntArray, item2: IntArray, item1: IntArray, position: Int) {
    // 外卦
    if (position == 1) {
        // 乾卦
        if (part == 1) {
            Column {
                val text1 = "壬戌(土)"
                val text2 = "壬申(金)"
                val text3 = "壬午(火)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))

                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 坎卦
        else if (part == 6) {
            Column {
                val text1 = "戊子(水)"
                val text2 = "戊戌(土)"
                val text3 = "戊申(金)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 震卦
        else if (part == 4) {
            Column {
                val text1 = "庚戌(土)"
                val text2 = "庚申(金)"
                val text3 = "庚午(火)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 艮卦
        else if (part == 7) {
            Column {
                val text1 = "丙寅(木)"
                val text2 = "丙子(水)"
                val text3 = "丙戌(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 坤卦
        else if (part == 8) {
            Column {
                val text1 = "癸酉(金)"
                val text2 = "癸亥(水)"
                val text3 = "癸丑(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 巽卦
        else if (part == 5) {
            Column {
                val text1 = "辛卯(木)"
                val text2 = "辛巳(火)"
                val text3 = "辛未(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 离卦
        else if (part == 3) {
            Column {
                val text1 = "己巳(火)"
                val text2 = "己未(土)"
                val text3 = "己酉(金)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 兑卦
        else if (part == 2) {
            Column {
                val text1 = "丁未(土)"
                val text2 = "丁酉(金)"
                val text3 = "丁亥(水)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
    }
    // 内卦
    else {
        // 乾卦
        if (part == 1) {
            Column {
                val text1 = "甲辰(土)"
                val text2 = "甲寅(木)"
                val text3 = "甲子(水)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 坎卦
        else if (part == 6) {
            Column {
                val text1 = "戊午(火)"
                val text2 = "戊辰(土)"
                val text3 = "戊寅(木)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 震卦
        else if (part == 4) {
            Column {
                val text1 = "庚辰(土)"
                val text2 = "庚寅(木)"
                val text3 = "庚子(水)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 艮卦
        else if (part == 7) {
            Column {
                val text1 = "丙申(金)"
                val text2 = "丙午(火)"
                val text3 = "丙辰(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 坤卦
        else if (part == 8) {
            Column {
                val text1 = "乙卯(木)"
                val text2 = "乙巳(火)"
                val text3 = "乙未(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 巽卦
        else if (part == 5) {
            Column {
                val text1 = "辛酉(金)"
                val text2 = "辛亥(水)"
                val text3 = "辛丑(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 离卦
        else if (part == 3) {
            Column {
                val text1 = "己亥(水)"
                val text2 = "己丑(土)"
                val text3 = "己卯(木)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
        // 兑卦
        else if (part == 2) {
            Column {
                val text1 = "丁丑(土)"
                val text2 = "丁卯(木)"
                val text3 = "丁巳(火)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item3[0] == 0) {
                        Text(text = "X", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item2[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                    if (item1[0] == 1) {
                        Text(text = "○", modifier = Modifier.width(10.dp))
                    } else {
                        Text(text = " ", modifier = Modifier.width(10.dp))
                    }
                }
            }
        }
    }
}

/**
 * 绘制变卦,及纳甲
 */
@Composable
fun drawBianPartGua(part: Int, position: Int) {
    // 外卦
    if (position == 1) {
        // 乾卦
        if (part == 1) {
            Column {
                val text1 = "壬戌(土)"
                val text2 = "壬申(金)"
                val text3 = "壬午(火)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))

                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 坎卦
        else if (part == 6) {
            Column {
                val text1 = "戊子(水)"
                val text2 = "戊戌(土)"
                val text3 = "戊申(金)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 震卦
        else if (part == 4) {
            Column {
                val text1 = "庚戌(土)"
                val text2 = "庚申(金)"
                val text3 = "庚午(火)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 艮卦
        else if (part == 7) {
            Column {
                val text1 = "丙寅(木)"
                val text2 = "丙子(水)"
                val text3 = "丙戌(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 坤卦
        else if (part == 8) {
            Column {
                val text1 = "癸酉(金)"
                val text2 = "癸亥(水)"
                val text3 = "癸丑(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 巽卦
        else if (part == 5) {
            Column {
                val text1 = "辛卯(木)"
                val text2 = "辛巳(火)"
                val text3 = "辛未(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 离卦
        else if (part == 3) {
            Column {
                val text1 = "己巳(火)"
                val text2 = "己未(土)"
                val text3 = "己酉(金)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 兑卦
        else if (part == 2) {
            Column {
                val text1 = "丁未(土)"
                val text2 = "丁酉(金)"
                val text3 = "丁亥(水)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
    }
    // 内卦
    else {
        // 乾卦
        if (part == 1) {
            Column {
                val text1 = "甲辰(土)"
                val text2 = "甲寅(木)"
                val text3 = "甲子(水)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 坎卦
        else if (part == 6) {
            Column {
                val text1 = "戊午(火)"
                val text2 = "戊辰(土)"
                val text3 = "戊寅(木)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 震卦
        else if (part == 4) {
            Column {
                val text1 = "庚辰(土)"
                val text2 = "庚寅(木)"
                val text3 = "庚子(水)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 艮卦
        else if (part == 7) {
            Column {
                val text1 = "丙申(金)"
                val text2 = "丙午(火)"
                val text3 = "丙辰(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 坤卦
        else if (part == 8) {
            Column {
                val text1 = "乙卯(木)"
                val text2 = "乙巳(火)"
                val text3 = "乙未(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 巽卦
        else if (part == 5) {
            Column {
                val text1 = "辛酉(金)"
                val text2 = "辛亥(水)"
                val text3 = "辛丑(土)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 离卦
        else if (part == 3) {
            Column {
                val text1 = "己亥(水)"
                val text2 = "己丑(土)"
                val text3 = "己卯(木)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
        // 兑卦
        else if (part == 2) {
            Column {
                val text1 = "丁丑(土)"
                val text2 = "丁卯(木)"
                val text3 = "丁巳(火)"

                val element1 = getFiveElementResult(extractElementFromText(text1))
                val element2 =  getFiveElementResult(extractElementFromText(text2))
                val element3 =  getFiveElementResult(extractElementFromText(text3))
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text1, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yinyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text2, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
                Row(
                    horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Text(text = element3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Text(text = text3, modifier = Modifier.width(40.dp), fontSize = 10.sp)
                    Image(
                        painterResource(id = R.mipmap.yangyao),
                        contentDescription = null,
                        modifier = Modifier.width(80.dp)
                    )
                }
            }
        }
    }
}

/**
 * 六爻生成
 */
fun sixLinesCreateContent(line: List<List<Int>>) {
    liu = generateSingleYao(line[0])
    wu = generateSingleYao(line[1])
    si = generateSingleYao(line[2])
    san = generateSingleYao(line[3])
    er = generateSingleYao(line[4])
    yi = generateSingleYao(line[5])
    // 判断上下卦,用来纳甲
    shang = judgeGua(liu, wu, si)
    xia = judgeGua(san, er, yi)
    // 变卦
    bianliu = generateBianSingleYao(liu)
    bianwu = generateBianSingleYao(wu)
    biansi = generateBianSingleYao(si)
    biansan = generateBianSingleYao(san)
    bianger = generateBianSingleYao(er)
    bianyi = generateBianSingleYao(yi)
    // 变卦上下卦
    bianshang = judgeBianGua(bianliu, bianwu, biansi)
    bianxia = judgeBianGua(biansan, bianger, bianyi)
    // 找卦宫
    findGuaGong(shang, xia)
}



fun findGuaGong(shang: Int, xia: Int) {
    var tempShang = ""
    var tempXia = ""
    when (shang) {
        1 -> tempShang = "乾"
        2 -> tempShang = "兑"
        3 -> tempShang = "离"
        4 -> tempShang = "震"
        5 -> tempShang = "巽"
        6 -> tempShang = "坎"
        7 -> tempShang = "艮"
        8 -> tempShang = "坤"
    }
    when (xia) {
        1 -> tempXia = "乾"
        2 -> tempXia = "兑"
        3 -> tempXia = "离"
        4 -> tempXia = "震"
        5 -> tempXia = "巽"
        6 -> tempXia = "坎"
        7 -> tempXia = "艮"
        8 -> tempXia = "坤"
    }
    guaGong = memoryViewiewModel.findPartGuaByName(tempShang, tempXia)
    when (guaGong) {
        "乾", "兑" -> fiveElements = "金"
        "离" -> fiveElements = "火"
        "震", "巽" -> fiveElements = "木"
        "坎" -> fiveElements = "水"
        "艮", "坤" -> fiveElements = "土"
    }
}

/**
 * 根据五行关系生成六亲
 */
fun getFiveElementResult(inputElement: String?): String {
    return when (fiveElements) {
        "金" -> when (inputElement) {
            "金" -> "兄弟"
            "水" -> "子孙"   // 金生水
            "木" -> "妻财"   // 金克木
            "火" -> "官鬼"   // 火克金
            "土" -> "父母"   // 土生金
            else -> "error"
        }

        "木" -> when (inputElement) {
            "木" -> "兄弟"
            "火" -> "子孙"   // 木生火
            "土" -> "妻财"   // 木克土
            "金" -> "官鬼"   // 金克木
            "水" -> "父母"   // 水生木
            else -> "error"
        }

        "水" -> when (inputElement) {
            "水" -> "兄弟"
            "木" -> "子孙"   // 水生木
            "火" -> "妻财"   // 水克火
            "土" -> "官鬼"   // 土克水
            "金" -> "父母"   // 金生水
            else -> "error"
        }

        "火" -> when (inputElement) {
            "火" -> "相同"
            "土" -> "子孙"   // 火生土
            "金" -> "妻财"   // 火克金
            "水" -> "官鬼"   // 水克火
            "木" -> "父母"   // 木生火
            else -> "error"
        }

        "土" -> when (inputElement) {
            "土" -> "兄弟"
            "金" -> "子孙"   // 土生金
            "水" -> "妻财"   // 土克水
            "木" -> "官鬼"   // 木克土
            "火" -> "父母"   // 火生土
            else -> "error"
        }

        else -> "Null"
    }
}

/**
 * 判断变卦上下卦是什么卦
 *  乾 1 兑 2 离 3 震 4 巽 5 坎 6 艮 7 坤 8
 */
fun judgeBianGua(i3: Int, i2: Int, i1: Int): Int {
    if (i3 == 1 && i2 == 1 && i1 == 1) {
        return 1
    } else if (i3 == 0 && i2 == 1 && i1 == 1) {
        return 2
    } else if (i3 == 1 && i2 == 0 && i1 == 1) {
        return 3
    } else if (i3 == 0 && i2 == 0 && i1 == 1) {
        return 4
    } else if (i3 == 1 && i2 == 1 && i1 == 0) {
        return 5
    } else if (i3 == 0 && i2 == 1 && i1 == 0) {
        return 6
    } else if (i3 == 1 && i2 == 0 && i1 == 0) {
        return 7
    } else if (i3 == 0 && i2 == 0 && i1 == 0) {
        return 8
    } else {
        return 999
    }
}

/**
 * 判断上下卦是什么卦
 * 用先天八卦顺序: 乾 1 兑 2 离 3 震 4 巽 5 坎 6 艮 7 坤 8
 */
fun judgeGua(item1: IntArray, item2: IntArray, item3: IntArray): Int {
    if (item1[1] == 1 && item2[1] == 1 && item3[1] == 1) {
        return 1
    } else if (item1[1] == 0 && item2[1] == 1 && item3[1] == 1) {
        return 2
    } else if (item1[1] == 1 && item2[1] == 0 && item3[1] == 1) {
        return 3
    } else if (item1[1] == 0 && item2[1] == 0 && item3[1] == 1) {
        return 4
    } else if (item1[1] == 1 && item2[1] == 1 && item3[1] == 0) {
        return 5
    } else if (item1[1] == 0 && item2[1] == 1 && item3[1] == 0) {
        return 6
    } else if (item1[1] == 1 && item2[1] == 0 && item3[1] == 0) {
        return 7
    } else if (item1[1] == 0 && item2[1] == 0 && item3[1] == 0) {
        return 8
    }
    return 0
}

/**
 * 生成单卦象
 * array[0] 老阳 1, 老阴 0, 少阳 2, 少阴 3
 * array[1] 阳爻 1, 阴爻 0
 */
fun generateSingleYao(size: List<Int>): IntArray {
    if (size[0] == 1 && size[1] == 1 && size[2] == 1) {
        return intArrayOf(1, 1)
    } else if (size[0] == 0 && size[1] == 0 && size[2] == 0) {
        return intArrayOf(0, 0)
    } else if (size[0] == 1 && size[1] == 1 && size[2] == 0) {
        return intArrayOf(2, 1)
    } else if (size[0] == 1 && size[1] == 0 && size[2] == 1) {
        return intArrayOf(2, 1)
    } else if (size[0] == 0 && size[1] == 1 && size[2] == 1) {
        return intArrayOf(2, 1)
    } else if (size[0] == 1 && size[1] == 0 && size[2] == 0) {
        return intArrayOf(3, 0)
    } else if (size[0] == 0 && size[1] == 1 && size[2] == 0) {
        return intArrayOf(3, 0)
    } else if (size[0] == 0 && size[1] == 0 && size[2] == 1) {
        return intArrayOf(3, 0)
    }
    return intArrayOf()
}

/**
 * 生成变爻单爻
 * 0 阴 , 1 阳
 */
fun generateBianSingleYao(size: IntArray): Int {
    if (size[0] == 1) {
        return 0
    } else if (size[0] == 0) {
        return 1
    } else {
        return size[1]
    }
}